package java3_BasicSyntax.Keywords;

import java.util.Scanner;

//break：打破循环、switch语句
//Continue：用于循环语句用，跳过此次剩余的循环体，直接进入下次循环
public class BreakAndContinue {
    public static void main(String[] args) {
//        break举例
        {
            for (int i = 0; i < 10; i++) {
                System.out.println("循环到第" + i + "次");
                if (i == 5) {
                    System.out.println("循环到第" + i + "次被break打破");
                    break;
                }
                System.out.println("循环结束");
            }
            Scanner scanner = new Scanner(System.in);
            int i = scanner.nextInt();
            switch (i) {
                case 1:
                    System.out.println(1);
                    break;
//                此处使用break会打断switch,不会执行case 2
                case 2:
                    System.out.println(2);

            }
        }
//        continue举例
        {
            int k = 0;
            do {
                k++;
                if (k % 2 == 0) {
                    System.out.println("跳过偶数 " + k);
                    continue;
                }
                System.out.println("奇数 " + k);
            } while (k < 10);

        }
    }
}
